<%@ page language="java"  pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'addStudent.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="js/jquery-3.3.1.min.js"></script>
	<script>
	$(function(){
		$.get("findGrades.do",function(data){
			var g=$("#gradeid");
			$.each(data,function(i,d){
				g.append("<option value='"+d.id+"'>"+d.gname+"</option>");
			});
		});
		
		$("input[name='sname']").blur(function(){
			if($(this).val()==""){
				alert("登录名不能为空");
	 			return false;
			}
			$.post("checkName.do",{name:$(this).val()},function(resp){
				if(resp=="true"){
	 				alert("此名称已经被使用");
	 			}else{
	 				alert("此名称可以使用");
	 			}
			},"text").fail(function(){
				alert("检查请求发生了错误！");
			});
		});
	});
	</script>
	<!-- <script type="text/javascript">
	function createAjax(){
		var r=new XMLHttpRequest();
		
		return r;
	}
	 function checkName(t){
	 	if(t.value==""){
	 		alert("登录名不能为空");
	 		return false;
	 	}
	 	let ajax=createAjax();
	 	ajax.onreadystatechange=function(){
	 		if(ajax.readyState==4&&ajax.status==200){
	 			console.log(ajax.getAllResponseHeaders());
	 			var resp=ajax.responseText;
	 			//???
	 			if(resp=="true"){
	 				alert("此名称已经被使用");
	 			}else{
	 				alert("此名称可以使用");
	 			}
	 		}
	 	}
	 	ajax.open("GET","checkName.do?name="+t.value,true);
	 	ajax.send(null);
	 }
	</script> -->
  </head>
  
  <body>
      <form action="addStudentServlet" method="post" enctype="multipart/form-data">
  		<fieldset style="align:center; width: 300px" >
			<legend>注册</legend>
			<!-- <p>学号：<input type="text" name="stuno" value="" /></p> --> 
	  		<p>姓名：<input type="text" name="sname" value="" /></p> 
	  		<p>性别：
	  			<input name="sex" type="radio" value="男" checked/>男
				<input name="sex" type="radio" value="女" />女
				<input name="sex" type="radio" value="妖" />妖
	  		</p> 
	  		<p>生日：<input type="text" name="bithday" value=""/></p> 
	  		<p>加入时间：<input type="text" name="enterdate" value=""/></p> 
	  		<p>QQ：<input type="text" name="qq" value=""/></p> 
	  		<p>祖籍：<input type="text" name="fromcity" value=""/></p> 
	  		
	  		<p>密码：<input type="password" name="pass" value="" /></p>
	 
			<p>年级：<select name="gradeid" id="gradeid">
		<%-- 	 
			<c:forEach items="${grades}" var="g" >
				 <option value="${g.id}" ><c:out value="${g.gname}"/></option>
			</c:forEach> --%>
			<%-- <%
				//GradeDao dao=new GradeDao();
				List<Grade> list=(List<Grade>)request.getAttribute("grades");
				for(Grade g:list){ %> 
				<option value="<%=g.getId()%>" ><%=g.getGname()%></option>
			<%	
				}
		    %> --%>
		    
		    
		    
		    
	  		</select></p>
	  		<p>
	  		照片：<input type="file" name="headpic" accept="image/*"/>
	  		</p>
	  		</p>	
		<p><input type="submit" name="submit"  value="提交" />
			<input type="button" style="margin-left: 50px" value ="返回" onclick="window.location.href='pages/Students.jsp'"/>
			</p>
		</fieldset>
  		</form>	
  </body>
</html>
